package org.grottarossa.ui.core.base;


import java.util.ResourceBundle;

import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.Notifier;
import org.grottarossa.ui.core.PopupViewer;

import com.vaadin.ui.Component;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;

/***
 * Classe generica da cui devono ereditare tutti i Panel
 * @author 
 *
 */
public abstract class BasePanel extends Panel implements IBaseComponent
{
	protected ResourceBundle m_localizer;


	/*** Gestisce le visualizzazioni in popup ***/
	private PopupViewer m_popupViewer = new PopupViewer();

	protected ApplicationSession m_appSession;

	public BasePanel(ApplicationSession appSession, ResourceBundle localizer)
	{
		this.m_appSession = appSession;
		m_localizer = localizer;
		setStyleName(".panel-noborder");
	}

	/***
	 * Inizializza i componenti grafici
	 */
	protected abstract void initializeComponents();

	public Window showInPopup(Component view, int width, int height, String caption,
			boolean sizable, boolean modal)
	{
		return m_popupViewer.showInPopup(view, width, height, caption, sizable, modal, getWindow());
	}

	public Window showInPopup(Component view, int width, int height, String caption,
			boolean sizable, boolean modal, Window activeWindow)
	{
		return m_popupViewer.showInPopup(view, width, height, caption, sizable, modal, activeWindow);
	}

	public void removePopupFromWindow(Window popup, Window activeWindow)
	{
		m_popupViewer.removePopupFromWindow(popup, activeWindow);
	}

	public void removePopup(Window popup)
	{
		m_popupViewer.removePopupFromWindow(popup, getWindow());
	}

	public void openUrl(String url)
	{
		m_popupViewer.openUrl(url, getWindow());
	}

	public void showWarning(String message)
	{
		m_appSession.getNotifier().showWarning(message);
	}

	public void showError(String message)
	{
		m_appSession.getNotifier().showError(message);
	}

	public void showError(Exception ex)
	{
		m_appSession.getNotifier().showError(ex);
	}

	public void showInfo(String message)
	{
		m_appSession.getNotifier().showInfo(message);
	}

	public void showInDetailArea(Component component)
	{
		//Per default non fa nulla, deve essere sovrascritto se serve nei pannelli specifici
	}
}
